import Vue from 'vue'
import App from './App.vue'
import element from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './assets/less/index.less'

import router from '../router'
import store from '../store'
import http from 'axios'
import '../api/mock.js'

Vue.config.productionTip = false
Vue.use(element)
Vue.prototype.$http = http
router.beforeEach((to,from,next)=>{
  store.commit('getToken')
  let token = store.state.user.token
  if(!token && to.name !== 'login') {
    // console.log("123+token",token)
    next({name:'login'})
  } 
  else if (token&&to.name === 'login') {
    // console.log("456+token",token)
    next({name:'home'})
  } 
  else {
    next()
  }
})
new Vue({
  store,
  router,
  render: h => h(App),
  created() {
    store.commit('addMenu', router)
  }
}).$mount('#app')
